using System.Collections.Generic;
using UnityEngine;

public class RuntimeAnimatorFactory : IBaseResourcesFactory<RuntimeAnimatorController>
{
    protected Dictionary<string , RuntimeAnimatorController> m_Anidict = new Dictionary<string , RuntimeAnimatorController>();

    protected string loadPath = string.Empty; // 动画控制器加载路径前缀

    public RuntimeAnimatorFactory()
    {
        //loadPath = ""; 构造的时候 给上动画控制器资源路径
    }

    public RuntimeAnimatorController GetSingleResources(string resPath)
    {
        RuntimeAnimatorController ItemGO = null; //动画控制器资源对象

        string path = loadPath + resPath; //资源最终路径

        if ( m_Anidict.ContainsKey(resPath) )
        {
            ItemGO = m_Anidict[resPath];
        }
        else
        {
            //通过ResourcesMgr加载动画控制器资源对象赋值给ItemGo  然后缓存进字典
            ItemGO = ( RuntimeAnimatorController )Resources.Load(path);
            m_Anidict.Add(resPath , ItemGO);
        }

        if ( ItemGO == null )
        {
            Debug.LogError(string.Format("资源加载异常: {0}资源加载失败,加载路径为{1}" , resPath , path));
        }

        return ItemGO;
    }
}